<template>
	<view class="wallet pages">
		<view class="container">
			<view class="add_sort" v-if="walletList.length==0">
				<view class="add_btn" @click="toAddWallet">
					<uni-icons type="plusempty" color="#fff" size="25"></uni-icons>
				</view>
				<view class="add_txt">
					{{$t('wallet.index.Add')}}
				</view>
			</view>
			<view class="wallet_sort" v-else>
				<view class="wallet_title">
					{{$t('wallet.index.My')}}
				</view>
				<view class="wallet_list">
					<view style="overflow-x: scroll;display: flex;" v-for="item in walletList" :key="item.id">
						<view class="wallet_item">
							<view class="wallet_name">
								<view class="wallet_img">
									<!-- <image src="../../static/img/index/xie.png" mode="widthFix"></image> -->
									<uni-icons type="wallet" size="30" color="gray"></uni-icons>
								</view>
							</view>
							<view class="wallet_num">
								{{item.address}}
							</view>
						</view>
						<view class="wallet_dele" @click="userWalletDel(item.id)">{{$t('wallet.index.Del')}}</view>
					</view>
					<view class="add" @click="toAddWallet">
						<view class="add_btn">
							<uni-icons type="plusempty" color="#fff" size="25"></uni-icons>
						</view>
						<view class="add_txt">
							{{$t('wallet.index.addWallet')}}
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { userWallet, userWalletDel } from '@/api/api.js'
	export default {
		data() {
			return {
				walletList: []
			}
		},
		onShow() {
			this.userWallet();
			uni.setNavigationBarTitle({
				title: this.$t('list.Wallet')
			})
		},
		methods: {
			toAddWallet() {
				uni.navigateTo({
					url: '/pages/shop/wallet/addWallet'
				})
			},
			userWallet() {
				userWallet({
					token: uni.getStorageSync('token')
				}).then(res => {
					this.walletList = res.data.data
				})
			},
			userWalletDel(id) {
				userWalletDel({
					token: uni.getStorageSync('token'),
					id: id
				}).then(res => {
					uni.showToast({
						title: res.data.msg,
						icon: "none"
					})
					setTimeout(() => {
						this.userWallet()
					}, 600)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wallet {
		width: 100%;
		
		.container {
			width: 100%;
			padding: 80rpx 40rpx 0;

			.add_sort {
				width: 100%;
				height: 248rpx;
				background: #f5f5f9;
				border: 2rpx solid #eeeef0;
				border-radius: 10rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				flex-direction: column;

				.add_btn {
					width: 80rpx;
					height: 80rpx;
					background-color: #01c2c3;
					display: flex;
					justify-content: center;
					align-items: center;
					border-radius: 10rpx;
				}

				.add_txt {
					margin-top: 20rpx;
					font-weight: 600;
				}
			}

			.wallet_sort {
				.wallet_title {
					font-size: 32rpx;
					font-weight: 600;
					margin-bottom: 30rpx;
				}

				.wallet_list {
					.wallet_item {
						display: flex;
						flex-shrink: 0;
						width: 670rpx;
						height: 160rpx;
						background: #e95052;
						border-radius: 8rpx;
						margin-bottom: 20rpx;

						.wallet_name {
							flex: 1;
							display: flex;
							align-items: center;
							padding-left: 40rpx;
							color: #fff;

							.wallet_img {
								width: 90rpx;
								height: 90rpx;
								display: flex;
								align-items: center;
								justify-content: center;
								background-color: #fff;
								border-radius: 50%;
								overflow: hidden;
								margin-right: 20rpx;

								uni-image {
									width: 50rpx;
									height: 50rpx;
								}
							}

							.wallet_info {
								font-size: 28rpx;
								line-height: 28rpx;
								font-weight: 600;

								uni-view:nth-child(2) {
									font-weight: 500;
									font-size: 24rpx;
									line-height: 24rpx;
									margin-top: 10rpx;
								}
							}
						}

						.wallet_num {
							flex: 1;
							padding-right: 50rpx;
							text-align: right;
							line-height: 160rpx;
							color: #fff;
							font-weight: 600;
							font-size: 38rpx;
						}
					}

					.add {
						width: 100%;
						height: 100rpx;
						background: #00c2c2;
						border-radius: 8rpx;
						margin-bottom: 20rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						font-size: 32rpx;
						color: #fff;
					}
				}

				.wallet_dele {
					width: 110rpx;
					height: 160rpx;
					flex-shrink: 0;
					background-color: #ddd;
					border-radius: 10rpx;
					margin-left: 5rpx;
					text-align: center;
					line-height: 160rpx;
					font-weight: bold;
				}
			}
		}
	}
</style>